from models import User, LocalUser
from django.contrib.auth.hashers import check_password
import logging

class LocalUserAuth:
    logger = logging.getLogger(__name__)
    def authenticate(self, username=None, password=None):
        logger.debug('DEBUG!')
	     try:
                user = User.objects.get(username=username)
		try:
                    localUser = LocalUser.objects.get(user = user.id)
                    if check_password(password, localUser.password):
                        return localUser.user
                    else: 
                        return None
                except LocalUser.DoesNotExist:
                    return None
            except User.DoesNotExist:
                return None
            
            return None
                 
    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None
